from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-12 14:02:52.165333
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 12, Dec, 2022
Time: 14:02:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1866
Nobs: 868.000 HQIC: -51.4917
Log likelihood: 11434.7 FPE: 3.59198e-23
AIC: -51.6808 Det(Omega_mle): 3.24011e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295767 0.049898 5.927 0.000
L1.Burgenland 0.106095 0.034148 3.107 0.002
L1.Kärnten -0.107347 0.018313 -5.862 0.000
L1.Niederösterreich 0.214672 0.071691 2.994 0.003
L1.Oberösterreich 0.087620 0.067956 1.289 0.197
L1.Salzburg 0.249708 0.036259 6.887 0.000
L1.Steiermark 0.029816 0.047613 0.626 0.531
L1.Tirol 0.129912 0.038657 3.361 0.001
L1.Vorarlberg -0.062685 0.033304 -1.882 0.060
L1.Wien 0.060614 0.060731 0.998 0.318
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064599 0.102736 0.629 0.529
L1.Burgenland -0.009257 0.070308 -0.132 0.895
L1.Kärnten 0.050555 0.037705 1.341 0.180
L1.Niederösterreich -0.174452 0.147606 -1.182 0.237
L1.Oberösterreich 0.367993 0.139916 2.630 0.009
L1.Salzburg 0.286180 0.074654 3.833 0.000
L1.Steiermark 0.108723 0.098031 1.109 0.267
L1.Tirol 0.312178 0.079591 3.922 0.000
L1.Vorarlberg 0.025863 0.068570 0.377 0.706
L1.Wien -0.026260 0.125040 -0.210 0.834
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199322 0.025853 7.710 0.000
L1.Burgenland 0.090363 0.017693 5.107 0.000
L1.Kärnten -0.008762 0.009488 -0.923 0.356
L1.Niederösterreich 0.267160 0.037144 7.193 0.000
L1.Oberösterreich 0.114721 0.035209 3.258 0.001
L1.Salzburg 0.052795 0.018786 2.810 0.005
L1.Steiermark 0.015951 0.024669 0.647 0.518
L1.Tirol 0.100092 0.020029 4.997 0.000
L1.Vorarlberg 0.056568 0.017255 3.278 0.001
L1.Wien 0.112856 0.031466 3.587 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105345 0.026542 3.969 0.000
L1.Burgenland 0.047927 0.018164 2.639 0.008
L1.Kärnten -0.016492 0.009741 -1.693 0.090
L1.Niederösterreich 0.196854 0.038134 5.162 0.000
L1.Oberösterreich 0.278749 0.036147 7.712 0.000
L1.Salzburg 0.118177 0.019287 6.127 0.000
L1.Steiermark 0.100421 0.025326 3.965 0.000
L1.Tirol 0.124462 0.020562 6.053 0.000
L1.Vorarlberg 0.070015 0.017715 3.952 0.000
L1.Wien -0.026276 0.032304 -0.813 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131876 0.047945 2.751 0.006
L1.Burgenland -0.053684 0.032812 -1.636 0.102
L1.Kärnten -0.037168 0.017596 -2.112 0.035
L1.Niederösterreich 0.166935 0.068885 2.423 0.015
L1.Oberösterreich 0.133147 0.065296 2.039 0.041
L1.Salzburg 0.290871 0.034840 8.349 0.000
L1.Steiermark 0.033996 0.045750 0.743 0.457
L1.Tirol 0.162628 0.037144 4.378 0.000
L1.Vorarlberg 0.108041 0.032001 3.376 0.001
L1.Wien 0.064966 0.058354 1.113 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060098 0.037979 1.582 0.114
L1.Burgenland 0.038579 0.025991 1.484 0.138
L1.Kärnten 0.049603 0.013938 3.559 0.000
L1.Niederösterreich 0.227164 0.054565 4.163 0.000
L1.Oberösterreich 0.271392 0.051723 5.247 0.000
L1.Salzburg 0.058597 0.027598 2.123 0.034
L1.Steiermark -0.007457 0.036239 -0.206 0.837
L1.Tirol 0.159021 0.029423 5.405 0.000
L1.Vorarlberg 0.068978 0.025348 2.721 0.007
L1.Wien 0.074680 0.046224 1.616 0.106
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184979 0.045645 4.053 0.000
L1.Burgenland 0.016203 0.031238 0.519 0.604
L1.Kärnten -0.059982 0.016752 -3.581 0.000
L1.Niederösterreich -0.094667 0.065581 -1.444 0.149
L1.Oberösterreich 0.182158 0.062164 2.930 0.003
L1.Salzburg 0.059048 0.033169 1.780 0.075
L1.Steiermark 0.228277 0.043555 5.241 0.000
L1.Tirol 0.486822 0.035362 13.767 0.000
L1.Vorarlberg 0.053120 0.030466 1.744 0.081
L1.Wien -0.054003 0.055555 -0.972 0.331
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158083 0.051773 3.053 0.002
L1.Burgenland 0.000124 0.035431 0.003 0.997
L1.Kärnten 0.066714 0.019001 3.511 0.000
L1.Niederösterreich 0.200609 0.074384 2.697 0.007
L1.Oberösterreich -0.069604 0.070509 -0.987 0.324
L1.Salzburg 0.220301 0.037621 5.856 0.000
L1.Steiermark 0.112750 0.049402 2.282 0.022
L1.Tirol 0.082676 0.040109 2.061 0.039
L1.Vorarlberg 0.123714 0.034555 3.580 0.000
L1.Wien 0.106386 0.063012 1.688 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358604 0.030573 11.729 0.000
L1.Burgenland 0.006876 0.020923 0.329 0.742
L1.Kärnten -0.024635 0.011221 -2.195 0.028
L1.Niederösterreich 0.228062 0.043926 5.192 0.000
L1.Oberösterreich 0.156973 0.041638 3.770 0.000
L1.Salzburg 0.052902 0.022217 2.381 0.017
L1.Steiermark -0.015939 0.029173 -0.546 0.585
L1.Tirol 0.118207 0.023686 4.991 0.000
L1.Vorarlberg 0.072070 0.020406 3.532 0.000
L1.Wien 0.048354 0.037211 1.299 0.194
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038283 0.158241 0.180106 0.167599 0.140379 0.124841 0.064705 0.220142
Kärnten 0.038283 1.000000 0.001254 0.132075 0.026787 0.099060 0.431402 -0.049372 0.102140
Niederösterreich 0.158241 0.001254 1.000000 0.345695 0.169572 0.311896 0.126663 0.191207 0.342984
Oberösterreich 0.180106 0.132075 0.345695 1.000000 0.234128 0.341400 0.177291 0.180264 0.274416
Salzburg 0.167599 0.026787 0.169572 0.234128 1.000000 0.152594 0.137180 0.152455 0.141955
Steiermark 0.140379 0.099060 0.311896 0.341400 0.152594 1.000000 0.157868 0.147611 0.094664
Tirol 0.124841 0.431402 0.126663 0.177291 0.137180 0.157868 1.000000 0.120754 0.167043
Vorarlberg 0.064705 -0.049372 0.191207 0.180264 0.152455 0.147611 0.120754 1.000000 0.020126
Wien 0.220142 0.102140 0.342984 0.274416 0.141955 0.094664 0.167043 0.020126 1.000000